<?php

@include_once("connect.php");

$res=[];
$tell=$_POST['tellnumber'];
$num=$_POST['num'];
$id=$_POST['id'];


if($tell&& $num&& $id){
   $sql="SELECT * FROM user_cart WHERE tellnumber='$tell' and goods_id='$id'";
   $a=mysqli_query($con,$sql);
   $arr=mysqli_fetch_array($a);
   if($arr){
     
     $sql="UPDATE user_cart SET num=num+ $num WHERE tellnumber='$tell' AND goods_id='$id'";
     $a=mysqli_query($con,$sql);
     if($a){
      $res['status']=true;
      $res['mag']="添加成功";
     }else{
      $res['status']=false;
      $res['mag']="数据库有误";
     }
   }else{
    $sql="INSERT INTO user_cart (tellnumber,num,goods_id) VALUES ('$tell','$num','$id')";
    $a=mysqli_query($con,$sql);
    if($a>0){
      $res['status']=true;
      $res['mag']="添加成功";
     }else{
      $res['status']=false;
      $res['mag']="数据库有误";
     }
   }

}else{
  $res['status']=false;
  $res['mag']="前端数据有误";
}
echo(json_encode($res,JSON_UNESCAPED_UNICODE));